package com.ruoyi.project.erp.Emp.controller;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.EmptyUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.erp.Emp.domain.TEmp;
import com.ruoyi.project.erp.Emp.service.ITEmpService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2020-08-24
 */
@Controller
@RequestMapping("/erp/Emp")
public class TEmpController extends BaseController
{
    private String prefix = "erp/Emp";

    @Resource
    private ITEmpService tEmpService;

    @RequiresPermissions("erp:Emp:view")
    @GetMapping()
    public String Emp()
    {
        return prefix + "/Emp";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    //@RequiresPermissions("erp:Emp:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestBody TEmp tEmp)
    {
        startPage();
        List<TEmp> list = tEmpService.selectTEmpList(tEmp);
        return getDataTable(list);
    }

    @PostMapping("/empLogin")
    @ResponseBody
    public AjaxResult empLogin(@RequestBody TEmp tEmp)
    {
        //startPage();
        List<TEmp> list = tEmpService.selectTEmpList(tEmp);
        if(list.size()>0){
            //登录成功，获取用户门店信息
           List<Map> resultList = tEmpService.selectTEmpInfo(list.get(0).getF102());
           return  new AjaxResult(AjaxResult.Type.SUCCESS,"成功",resultList);
        }else{
            return error("用户名或者密码错误，请重新登录");
        }
    }

    @PostMapping("/getDdate")
    @ResponseBody
    public AjaxResult getDdate()
    {
            return  new AjaxResult(AjaxResult.Type.SUCCESS,"成功",tEmpService.getDdate());
    }

    //电脑端登录
    @PostMapping("/empLoginPc")
    @ResponseBody
    public AjaxResult empLoginPc(String username,String password)
    {
        //startPage();
        List<Map> resultList= tEmpService.selectTEmpPc(username,password);
        if(resultList.size()>0){
            //登录成功，获取用户门店信息
            return  new AjaxResult(AjaxResult.Type.SUCCESS,"成功",resultList);
        }else{
            return error("用户名或者密码错误，请重新登录");
        }
    }


    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("erp:Emp:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TEmp tEmp)
    {
        List<TEmp> list = tEmpService.selectTEmpList(tEmp);
        ExcelUtil<TEmp> util = new ExcelUtil<TEmp>(TEmp.class);
        return util.exportExcel(list, "Emp");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("erp:Emp:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TEmp tEmp)
    {
        return toAjax(tEmpService.insertTEmp(tEmp));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{fitemid}")
    public String edit(@PathVariable("fitemid") Long fitemid, ModelMap mmap)
    {
        TEmp tEmp = tEmpService.selectTEmpById(fitemid);
        mmap.put("tEmp", tEmp);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("erp:Emp:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TEmp tEmp)
    {
        return toAjax(tEmpService.updateTEmp(tEmp));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("erp:Emp:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tEmpService.deleteTEmpByIds(ids));
    }
}
